package com.demo.servlet.demo1208;

import javax.servlet.*;
import java.io.IOException;

public class Demo01Servlet implements Servlet {
    public Demo01Servlet() {
        System.out.println("Demo01Servlet 的 无参构造函数");
    }

    @Override
    public void init(ServletConfig config) throws ServletException {
        //Servlet 初始化方法
        System.out.println("Demo01Servlet 的 init()");
        //1.可以获取 Servlet 程序的别名 servlet-name
        System.out.println("Demo01Servlet 的别名是" + config.getServletName());
        //2.获取初始化参数
        System.out.println("初始化参数 username：" + config.getInitParameter("username"));
        System.out.println("初始化参数 password：" + config.getInitParameter("password"));
        //3.获取ServletContext对象
        System.out.println(config.getServletContext());
    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
        System.out.println("Demo01Servlet 的 service()");
    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {
        System.out.println("Demo01Servlet 被摧毁");
    }
}
